package com.hspedu.homework.homework13;

public class Homework013 {
    public static void main(String[] args) {
        Person[] p = new Person[4];
        p[0] = new Student("小刘", "男", 20, "210110333");
        p[1] = new Student("小王", "女", 19, "210110334");
        p[2] = new Teacher("万老师", "男", 28, 5);
        p[3] = new Teacher("宋老师", "女", 27, 4);

        System.out.println("======排序前======");
        printArr(p);
        System.out.println("======排序后======");
        arrSort(p);
        printArr(p);

    }

    public static void printArr(Person[] p) {
        for (int i = 0; i < p.length; i++) {
            p[i].printInfo();
            if(p[i] instanceof Student){
                ((Student)p[i]).study();
            }else if(p[i] instanceof  Teacher){
                ((Teacher)p[i]).teach();
            }
            p[i].play();
            if(i != p.length -1){
                System.out.println("------------------");
            }
        }
    }

    public static void arrSort(Person[] p) {
        //使用冒泡排序
        for (int i = 0; i < p.length - 1; i++) {
            for (int j = 0; j < p.length - 1 - i; j++) {
                if (p[j].getAge() < p[j + 1].getAge()) {
                    Person tem = p[j];
                    p[j] = p[j + 1];
                    p[j + 1] = tem;
                }
            }
        }
    }

}
